package com.mew.slots.core.game.zzdzz.service;

import com.alibaba.fastjson.JSON;
import com.mew.common.enm.SlotsWinType;
import com.mew.common.entity.game.WinFree;
import com.mew.slots.core.common.game.BaseGameService;
import com.mew.slots.core.common.game.vo.BasePlayMsgs;
import com.mew.slots.core.common.messge.response.SlotsPlayResponseMessage;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.zzdzz.dto.ZzdzzInRoomList;
import com.mew.slots.core.game.zzdzz.dto.ZzdzzPlayMsgs;
import com.mew.slots.core.game.zzdzz.message.ZzdzzPlayResponseMessage;
import com.mew.slots.core.game.zzdzz.roller.ZzdzzXml;
import com.mew.slots.core.game.zzdzz.room.ZzdzzRoom;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class ZzdzzService extends BaseGameService {
    @Override
    public BasePlayMsgs startGame(StrategyGameVO player) {
        WinFree winFree=player.getWinFree();
        ZzdzzInRoomList voList;
        if (StringUtils.isNotEmpty(winFree.getJson())){
            voList = JSON.parseObject(winFree.getJson(),ZzdzzInRoomList.class);
        }else{
            voList = new ZzdzzInRoomList();
        }
        ZzdzzRoom room = new ZzdzzRoom(voList,winFree.getFreeType(),winFree.getFreeNumber());
        room.init(player.getRollerId(), ZzdzzXml.getInstance(),player.getWinType()== SlotsWinType.Free.code(),player.getInBetNumber(),player.getControlType(),50);
        room.roundPlay243();
        winFree.setJson(JSON.toJSONString(voList));
        System.out.println(voList);
        return room.getRes();
    }

    @Override
    public SlotsPlayResponseMessage myResp(WinFree winFree, BasePlayMsgs res) {
        ZzdzzPlayResponseMessage message = new ZzdzzPlayResponseMessage();
        ZzdzzPlayMsgs pmres=(ZzdzzPlayMsgs) res;
        if(pmres.getBouns()>0){
            message.setBonus(pmres.getBouns());
            winFree.setBounsNumber(pmres.getBouns());
        }
        message.setProgressBar(pmres.getProgressBar());
        message.setFreeCoins(pmres.getFreeCoins());
        if(pmres.getFree()==1&&winFree.getFrees()==0){
            winFree.setFreeType(pmres.getFreeType());
            message.setFreeType(pmres.getFreeType());
        }
        message.setScatterCoin(pmres.getScatterCoin());
        message.setRoulettes(pmres.getRoulettes());
        message.setRow(pmres.getRow());
        message.setCol(pmres.getCol());
        message.setCourse(pmres.getCourse());
        return message;
    }

    @Override
    public void myAfterResp(SlotsPlayResponseMessage message, StrategyGameVO player, BasePlayMsgs res) {}

}
